home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Henry Cross <hcross@ix.netcom.com>
- Newsgroups: comp.lang.c
- Subject: fseek() and CR/LF pair
- Date: Sat, 09 Mar 1996 18:25:00 -0800
- Organization: i586 Box @Irvine, Ca.
- Message-ID: <31423D7C.78A5@ix.netcom.com>
- NNTP-Posting-Host: irv-ca7-27.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Sat Mar 09 8:21:30 PM CST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hi boys and girls!
- I got problems right here in river city! Seems my 16-bit MSDOS
- program using MSVC 1.52 is causing me some consternation. I have
- a ASCII data file I must read in in 80 byte records. Sometimes the
- file will have the CR/LF pair every 80th character, sometimes not.
- (i.e. sometimes its a text file, sometimes its a binary file.)
-
- I've opened the file using fopen(filename, "rb") and am getting an
- erroneous position after certain fseek's(fptr, -80L, SEEK_CUR);
- (i.e. I read an 80 byte record then read 1 byte to determine if
- CR or LF if YES then read another byte until != CR/LF pair then
- fseek -1L and read 80 bytes to determine if this record belongs
- with the previous data if not then fseek(fptr, -80L, SEEK_CUR)
- process the current data then return to reading 80 bytes, etc.)
-
- My problem is that after certain fseeks -80L where I have to back
- over the default 512 byte buffer boundary the file pointer is at the
- wrong position! Caused by the CR/LF pair and my fseek'ing backwards
- over a 512 byte buffer boundary even though I'm using binary mode!
- fseek -80L's that are within the 512 byte buffer work fine. Just don't
- backup past it! I cannot create a buffer large enough with malloc and
- setvbuf() to read in the largest possible file. (Hey! We're talking
- 16 bits here! You guys remember the old 64K boundary PITA right? :) )
-
- I know this can happen in text mode but I fopen'ed the file in main()
- as "rb"! Personally I think it's a library bug. I ran across this
- problem along time ago and seem to recall I didn't have this problem
- with a Watcom compiler. I'm going to try another compiler but my problem
- is I'm stuck using MSVC at this point due to vendor library extensions.
- Any idea's, comments or useful insult's will be dolefully reviewed.
-
- Thanx,
- H.Cross
-